﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Nova_Common;
using Nova_BLL;
using Nova_DAL;
using Nova_MOD;

public partial class System_User_Pwd : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    Nova_MOD.Users Nova_MOD_Users = new Nova_MOD.Users();
    Nova_BLL.Users Nova_BLL_Users = new Nova_BLL.Users();
    protected int iCount = 0;


    protected void Page_Load(object sender, EventArgs e)
    {
        LoginLogic.IsLogin();

        if (!IsPostBack)
        { 
        }

        //验证TextBox
        string strJs = "";
        strJs = "return Validate(";
        strJs += "'txtOldvPwd','原始密码不为空','r'";
        strJs += ",'txtNewPwd','新密码不为空','r'";
        strJs += ",'txtvPassWord','确认密码不为空','r'";
        strJs += ");";
        ibtnSubmit.Attributes.Add("onclick", strJs);
    }
    
    /// <summary>
    /// 确定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            HttpCookie cookies = Request.Cookies["vNovaUserNo"];

            ds = Nova_BLL_Users.GetUserDataSet(cookies.Value.ToString());
            if (txtOldvPwd.Text.Trim() != ds.Tables[0].Rows[0]["vPassWord"].ToString())
            {
                 ShowBox.MessageBox(this.Page, "原始密码不正确！");
                 return;
            }

            if (txtNewPwd.Text.Trim() != txtvPassWord.Text.Trim())
            {
                ShowBox.MessageBox(this.Page, "确认密码与新密码不符！");
                return;
            }

            Nova_MOD_Users.vUserNo = cookies.Value.ToString();
            Nova_MOD_Users.vPassWord =txtvPassWord.Text.Trim();
            
            iCount = Nova_BLL_Users.UpdateUserPwd(Nova_MOD_Users);
            
            if (iCount > 0)
            {
                ShowBox.MessageBox(this.Page, "操作成功！", "Pwd.aspx");
                return;
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }



    /// <summary>
    /// 清空
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
    {
        txtOldvPwd.Text = "";
        txtNewPwd.Text = "";
        txtvPassWord.Text = "";
    }
}
